<?php
/**
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file license.txt or that can be found at 
 * http://code.google.com/p/billboardce/wiki/License.
 *
 * @package    Slide_Stream_Map
 * @category   Model
 * @license    http://code.google.com/p/billboardce/wiki/License New BSD License
 * @version    SVN: $Id: $
 */
class Slide_Stream_Map extends Ot_Db_Table
{
    /**
     * Name of the table in the database
     *
     * @var string
     */
    protected $_name = 'tbl_slide_stream_map';
  
    /**
     * Primary key of the table
     *
     * @var string
     */
    protected $_primary = 'slideStreamMapId';
    
    /**
     * Returns an array of all the slides & slideStreams that are in a given 
     * slide stream ID
     * 
     * @param in $slideStreamId The slide stream ID to get the entities for
     * @return array The entities in the slide stream
     */
    public function getEntitiesForSlideStream ($slideStreamId) {
        
        $entities = $this->fetchAll($this->getAdapter()->quoteInto('slideStreamId = ?', $slideStreamId, 'order'))->toArray();
        
        $entityList = array();
        
        $slide = new Slide();
        $slideStream = new Slide_Stream();
        
        foreach ($entities as $e) {
            
            $tmpData = array();
            
            if ($e['entityType'] == 'slide') {
                
                $tmpData = $slide->find($e['entityTypeId']);

            } else if ($e['entityType'] == 'slideStream') {
                $tmpData = $slideStream->find($e['entityTypeId']);
            }
            
            if (!is_null($tmpData)) {
                $e['data'] = $tmpData->toArray();
            }
            
            $e['data'] = $tmpData;
            $entityList[] = $e;
        }
    }
}